package com.zhika.zishi.fragments.channel;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ListView;

import com.zhika.zishi.R;
import com.zhika.zishi.adapter.CompareShowAdapter;
import com.zhika.zishi.beans.CompareShowBean;
import com.zhika.zishi.customview.LoadListView;
import com.zhika.zishi.customview.OptionsPopView;
import com.zhika.zishi.customview.RefreshableView;
import com.zhika.zishi.interfaces.ChannelPopInterface;

import java.util.ArrayList;

/**
 * Created by shi-02 on 2015/4/23.
 * 对比秀
 */
public class ChannelCompareFragment extends Fragment {

    private final String TAG = "ChannelCompareFragment";

    private OptionsPopView optionsPopView;

    private Context context;

    private LoadListView listView;

    private RefreshableView refreshableView;

    private View view;

    private ArrayList<CompareShowBean> compareShowBeans = new ArrayList<>();

    private CompareShowAdapter adapter;

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.compare_of_channel,container,false);

        addTestData();
        initView();


        return view;
    }

    private void initView(){
        context = getActivity();

        refreshableView = (RefreshableView) view.findViewById(R.id.compare_of_channel_refresh_view);
        refreshableView.setOnRefreshListener(new RefreshableView.PullToRefreshListener() {
            @Override
            public void onRefresh() {

            }
        },11);
        listView = (LoadListView) view.findViewById(R.id.compare_of_channel_list_view);
        adapter = new CompareShowAdapter(context,compareShowBeans);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                optionsPopView.hideOptions();

            }
        });
        listView.setInterface(new LoadListView.ILoadListener() {
            @Override
            public void onLoad() {

            }
        });

        listView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                optionsPopView.hideOptions();
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            }
        });
        optionsPopView = (OptionsPopView) view.findViewById(R.id.compare_of_channel_options_pop_view);
        optionsPopView.setPopInterface(new ChannelPopInterface() {
            @Override
            public void heatListener() {

            }

            @Override
            public void timeListener() {

            }
        });
    }


    /**
     * 测试数据
     */
    private void addTestData(){
        for (int i=0;i<10;i++){
            CompareShowBean bean = new CompareShowBean();
            bean.setNickname("攻略者昵称");
            bean.setFeelStr("哈哈哈哈哈哈哈，感受啊");
            bean.setLikeNumStr("111");
            bean.setDislikeNumStr("10");

            bean.setStrategyTitleStr("机器人进化史");

            compareShowBeans.add(bean);
        }
    }
}
